package com.ruoyi.ldzlsb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.ldzlsb.domain.SbInspectionDetail;
import com.ruoyi.ldzlsb.service.ISbInspectionDetailService;

/**
 * 巡检明细Controller
 * 
 * @author anli
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/inspection/detail")
public class SbInspectionDetailController extends BaseController
{
    @Autowired
    private ISbInspectionDetailService sbInspectionDetailService;

    /**
     * 查询巡检明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SbInspectionDetail sbInspectionDetail)
    {
        startPage();
        List<SbInspectionDetail> list = sbInspectionDetailService.selectSbInspectionDetailList(sbInspectionDetail);
        return getDataTable(list);
    }

    /**
     * 导出巡检明细列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, SbInspectionDetail sbInspectionDetail)
    {
        List<SbInspectionDetail> list = sbInspectionDetailService.selectSbInspectionDetailList(sbInspectionDetail);
        ExcelUtil<SbInspectionDetail> util = new ExcelUtil<SbInspectionDetail>(SbInspectionDetail.class);
        util.exportExcel(response, list, "巡检明细数据");
    }

    /**
     * 获取巡检明细详细信息
     */
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(sbInspectionDetailService.selectSbInspectionDetailByDetailId(detailId));
    }

    /**
     * 新增巡检明细
     */
    @PostMapping
    public AjaxResult add(@RequestBody SbInspectionDetail sbInspectionDetail)
    {
        return toAjax(sbInspectionDetailService.insertSbInspectionDetail(sbInspectionDetail));
    }

    /**
     * 修改巡检明细
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SbInspectionDetail sbInspectionDetail)
    {
        return toAjax(sbInspectionDetailService.updateSbInspectionDetail(sbInspectionDetail));
    }

    /**
     * 删除巡检明细
     */
    @DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(sbInspectionDetailService.deleteSbInspectionDetailByDetailIds(detailIds));
    }

    /**
     * 根据巡检单ID查询巡检明细列表
     */
    @GetMapping("/record/{recordId}")
    public AjaxResult listByRecordId(@PathVariable("recordId") Long recordId)
    {
        return success(sbInspectionDetailService.selectSbInspectionDetailByRecordId(recordId));
    }

    /**
     * 批量新增巡检明细
     */
    @PostMapping("/batch")
    public AjaxResult batchAdd(@RequestBody List<SbInspectionDetail> detailList)
    {
        return toAjax(sbInspectionDetailService.batchInsertSbInspectionDetail(detailList));
    }

    /**
     * 批量修改巡检明细
     */
    @PutMapping("/batch")
    public AjaxResult batchEdit(@RequestBody List<SbInspectionDetail> detailList)
    {
        return toAjax(sbInspectionDetailService.batchUpdateSbInspectionDetail(detailList));
    }
} 